import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'tp_update_widget.dart';

/**
 * author：lx
 * date：2021-0126
 * descr：根据蒲公英上面的api版本路径，获取版本更新
 */
class UpdateUtils{
  //初始化下载
  static initializeFlutterDownloader() async{
    await FlutterDownloader.initialize();
  }
  //弹出更新
 static void popDialog(
     bool needForceUpdate,
     String buildVersionNo,
     String buildVersion,
     String buildUpdateDescription,
     String buildName,
     String? buildFileSize,
     String downloadURL,
     String package_name,
     BuildContext context,
     ) {
   showDialog(
       context: context,
       barrierDismissible: false,
       builder: (_) {
         return WillPopScope(
             child: TPUpdteWidget(
               needForceUpdate: needForceUpdate,
               buildVersionNo: buildVersionNo,
               buildVersion: buildVersion,
               buildUpdateDescription: buildUpdateDescription,
               buildName: buildName,
               buildFileSize: (
                   (
                       (double.parse(
                           (buildFileSize)!
                       ))
                   /
                       (1024*1024)
               ).toStringAsFixed(2)),
               url: downloadURL,
               packageName: package_name,
               width: MediaQuery.of(context).size.width*0.7,
               onClose: ()=>_close(context),
             ),
             onWillPop: () async{
               return false;
             });
       });

 }

  static _close(context) {
    Navigator.pop(context!);
  }
}